import { registerMicroApps, start } from 'qiankun';

// 子应用加载过程
function loader(loading) {
  console.log('🚀 ~ loader ~ loading:', loading);
}

// 注册子应用
registerMicroApps(
  [
    {
      name: 'sub',
      entry: '//localhost:3001',
      activeRule: '/sub',
      container: '#subapp-container',
      loader,
      props: {
        token: 'jkqwjekqjekqjkejjj',
      },
    },
  ],
  {
    beforeLoad: [
      (app) => {
        console.log('🚀 ~ app: [LifeCycle] before load', app.name);
      },
    ],
    beforeMount: [
      (app) => {
        console.log('🚀 ~ app: [LifeCycle] before mount', app.name);
      },
    ],
    afterMount: [
      (app) => {
        console.log('🚀 ~ app: [LifeCycle] after mount', app.name);
      },
    ],
    beforeUnmount: [
      (app) => {
        console.log('🚀 ~ app: [LifeCycle] before unmount', app.name);
      },
    ],
    afterUnmount: [
      (app) => {
        console.log('🚀 ~ app: [LifeCycle] after unmount', app.name);
      },
    ],
  },
);

// 启动微服务
start({
  prefetch: false, // 开启预加载
  sandbox: {
    strictStyleIsolation: true, // 开启严格的样式隔离模式
  },
  singular: true, // 单实例场景
});

// export const startApp = (ops) => {
//   let options = {
//     prefetch: true, // 开启预加载
//     sandbox: {
//       strictStyleIsolation: true, // 开启严格的样式隔离模式
//     },
//     singular: true, // 单实例场景
//     ...ops,
//   };
//   start(options);
// };
